﻿using System;
using System.Collections.Generic;
using System.Text;
using Facebook.Web;
using System.ComponentModel;

namespace Facebook.Web.FbmlControls
{
    /// <summary>
    /// Represents common functionality for buttons represented in FBML.
    /// Derived from http://facebookui.codeplex.com/ 
    /// Copyright (c) 2009, Robert Paveza
    /// All rights reserved.
    /// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
    /// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
    /// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
    /// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
    /// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
    /// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
    /// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
    /// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
    /// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
    /// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
    /// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    /// </summary>
    [DefaultProperty("Text")]
    public abstract class FbmlButtonBase : FbmlControl
    {
        /// <summary>
        /// Gets or sets the label that should be displayed on the button face.
        /// </summary>
        [FbmlRequired(IsRequired = true)]
        [Browsable(true)]
        [DefaultValue(null)]
        [Category(FbmlConstants.REQUIRED)]
        [Description("Specifies the text that should be displayed on the button.")]
        public string Text
        {
            get;
            set;
        }

        /// <inheritdoc />
        protected override void AddAttributesToRender(System.Web.UI.HtmlTextWriter writer)
        {
            if (string.IsNullOrEmpty(Text))
                throw new MissingRequiredAttribute("Text", Text);

            base.AddAttributesToRender(writer);

            writer.AddAttribute("label", Text, true);
        }
    }
}
